import request from "./request";

// 登录
export function login(userInfo) {
  return request({
    method: "POST",
    url: "/pomelo/user/login",
    data: {
      userName: userInfo.userName,
      passWord: userInfo.passWord,
    },
  });
}

// 注册
export function register(userInfo) {
  return request({
    method: "POST",
    url: "/pomelo/user/addUser",
    data: {
      userName: userInfo.userName,
      passWord: userInfo.passWord,
      schoolId: userInfo.schoolId,
    },
  });
}

// 更新用户信息
export function updateUserInfo(data) {
  return request({
    method: "POST",
    url: "/pomelo/user/updateUser",
    data,
  });
}

// 获取用户信息
export function getUserById(userId) {
  return request({
    url: `/pomelo/user/getUserById/${userId}`,
  });
}

// 请求首页数据
export function getHomeData() {
  return request({
    url: "/pomelo/note",
  });
}

// 获取笔记的详细信息
export function getNoteDetail(noteId) {
  return request({
    url: `/pomelo/note/getNoteById/${noteId}`,
  });
}

// 获取笔记的评论
export function getNoteComment(noteId) {
  return request({
    url: `/pomelo/comment/${noteId}`,
  });
}

// 添加评论
export function addComment(data) {
  return request({
    method: "POST",
    url: "/pomelo/comment/addComment",
    data,
  });
}

// 给笔记点赞
export function likeNote(data) {
  return request({
    method: "POST",
    url: "/pomelo/like/addLike",
    data,
  });
}

// 判断点没点过赞
export function isLikeNote(noteId, userId) {
  return request({
    url: `/pomelo/like/isNotLike/${noteId}/${userId}`,
  });
}

// 取消点赞
export function deleteLikeNote(data) {
  return request({
    method: "POST",
    url: "/pomelo/like/deleteLike",
    data,
  });
}

// 判断是否收藏过笔记
export function isCollectNote(noteId, userId) {
  return request({
    url: `/pomelo/collection/isNotCollection/${noteId}/${userId}`,
  });
}

// 收藏笔记
export function collectNote(data) {
  return request({
    method: "POST",
    url: "/pomelo/collection/addCollection",
    data,
  });
}

// 取消收藏
export function deleteCollectNote(data) {
  return request({
    method: "POST",
    url: "/pomelo/collection/deleteCollection",
    data,
  });
}

// 请求个人的所有笔记
export function getAllMyNote(userId) {
  return request({
    url: `/pomelo/user/Noted/${userId}`,
  });
}

// 请求收藏的笔记
export function getCollectNote(userId) {
  return request({
    url: `/pomelo/user/Collectioned/${userId}`,
  });
}

// 搜索功能
// 1. 搜索note笔记
export function getSearchForNote(data) {
  return request({
    url: `/pomelo/note/queryNotes/${data}`,
  });
}
// 2. 搜索user
export function getSearchForUser(data) {
  return request({
    url: `/pomelo/user/queryUsers/${data}`,
  });
}

// 获取关注列表
export function getCircusList(userId) {
  return request({
    url: `/pomelo/follow/allFollow/${userId}`,
  });
}

// 获取粉丝列表
export function getFansList(userId) {
  return request({
    url: `/pomelo/follow/allFan/${userId}`,
  });
}

// 判断是否关注了笔记的发布者
export function isCircusUser(userId, toUserId) {
  return request({
    url: `/pomelo/follow/isNotFollow/${userId}/${toUserId}`,
  });
}

// 新增关注
export function addCircusUser(data) {
  return request({
    method: "post",
    url: `/pomelo/follow/addFollow`,
    data,
  });
}

// 取消关注
export function cancelCircusUser(data) {
  return request({
    method: "post",
    url: `/pomelo/follow/deleteFollow`,
    data,
  });
}
